home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / c-runtime / include / objc-proto.h next >
Encoding:
C/C++ Source or Header  |  1992-04-21  |  9.9 KB  |  357 lines

  1. /* -*-c-*- */
  2.  
  3. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* As a special exception, if you link this library with files
  22.    compiled with GCC to produce an executable, this does not cause
  23.    the resulting executable to be covered by the GNU General Public License.
  24.    This exception does not however invalidate any other reasons why
  25.    the executable file might be covered by the GNU General Public License.  */
  26.  
  27. /* 
  28.   $Header: /usr/user/dennis_glatting/ObjC/c-runtime/include/RCS/objc-proto.h,v 0.13 1992/04/13 11:40:53 dennisg Exp dennisg $
  29.   $Author: dennisg $
  30.   $Date: 1992/04/13 11:40:53 $
  31.   $Log: objc-proto.h,v $
  32.  * Revision 0.13  1992/04/13  11:40:53  dennisg
  33.  * Check in after array version of run-time works.
  34.  * Expect more changes as hash version and other changes are made.
  35.  *
  36.  * Revision 0.12  1992/01/03  02:57:08  dennisg
  37.  * modified to handle new initialization scheme.
  38.  * fixed code structure.
  39.  *
  40.  * Revision 0.11  1991/12/10  12:03:22  dennisg
  41.  * Cleaned up file format for a distribution.
  42.  * Added a prototype for archiving.  Now all I have to do is write it.
  43.  *
  44.  * Revision 0.10  1991/12/07  00:57:20  dennisg
  45.  * added objc_classSize() prototype.
  46.  *
  47.  * Revision 0.9  1991/12/06  00:36:24  dennisg
  48.  * added type decls for objc_msgSend*().
  49.  *
  50.  * Revision 0.8  1991/12/01  01:29:29  dennisg
  51.  * modified to remove changes previously made to
  52.  * implement posing.  posing just got easy.
  53.  *
  54.  * Revision 0.7  1991/11/29  22:00:10  dennisg
  55.  * modified to implement set functions.
  56.  *
  57.  * Revision 0.6  1991/11/29  20:02:01  dennisg
  58.  * fixed several const decls.  bozo.
  59.  *
  60.  * Revision 0.5  1991/11/29  13:32:16  dennisg
  61.  * committed some functions to inline and changes prototypes
  62.  * to match.
  63.  * also added some documentation.
  64.  *
  65.  * Revision 0.4  1991/11/29  00:24:14  dennisg
  66.  * many changes including posing, things to make the compiler
  67.  * happier, structure changes, and things to make it play better.
  68.  *
  69.  * Revision 0.3  1991/11/16  16:26:02  dennisg
  70.  * changed some prototypes to make
  71.  * the compiler happier.
  72.  *
  73.  * Revision 0.2  1991/11/07  22:31:42  dennisg
  74.  * added copyleft.
  75.  *
  76.  * Revision 0.1  1991/10/24  00:19:24  dennisg
  77.  * Initial check in.  Preliminary development stage.
  78.  *
  79.  */
  80.  
  81.  
  82. #ifndef _objc_proto_INCLUDE_GNU
  83. #define _objc_proto_INCLUDE_GNU
  84.  
  85. #include  <objc.h>
  86. #include  <objc-protoP.h>
  87.  
  88. #include  <stdlib.h>
  89.  
  90.  
  91. /*
  92.  * Compiler defined prototypes.
  93.  *  These prototypes can't be defined if we're
  94.  *  compiling Objective-C code.
  95.  */
  96. #ifndef __OBJC__
  97. /*
  98.  * objc_getClass() returns the id of the class 
  99.  *  object for the aClassName class.   The class 
  100.  *  object holds information used by instances of 
  101.  *  the class.  
  102.  *
  103.  * Print a message to the standard error stream if 
  104.  *  aClassName isn't part of the executable image.
  105.  */
  106. Class_t 
  107. objc_getClass (const char*);
  108.  
  109. /*
  110.  * objc_getMetaClass() returns the id of the 
  111.  *  meta class object for the aClassName class.  
  112.  *  The meta class object holds information used 
  113.  *  by the class object, just as the class 
  114.  *  object holds information used by instances 
  115.  *  of the class.  
  116.  *
  117.  * Print a message to the standard error stream 
  118.  *  if aClassName isn't part of the executable image.
  119.  */
  120. MetaClass_t 
  121. objc_getMetaClass (const char*);
  122.  
  123. /*
  124.  * The compiler converts every message expression into a 
  125.  *  call on one of these two functions.  Messages to 
  126.  *  super are converted to calls on objc_msgSendSuper(); 
  127.  *  all others are converted to calls on objc_msgSend().
  128.  *
  129.  * These functions return the address of the method 
  130.  *  implementation.  The compiler then generates calls
  131.  *  to those methods passing the full argument array.
  132.  *
  133.  * Calls to objc_msgSend() and objc_msgSendSuper() 
  134.  *  should be generated only by the compiler.  You shouldn't 
  135.  *  call them directly in the Objective-C code you write.
  136.  */
  137. IMP  
  138. objc_msgSend (id, SEL);
  139.  
  140. IMP 
  141. objc_msgSendSuper (Super_t, SEL);
  142. #endif
  143.  
  144. /*
  145.  * Given the name of a variable within a class's 
  146.  *  definition, return a pointer to a structure that
  147.  *  describes it.
  148.  */
  149. Ivar_t  
  150. object_getIvarAddress (id aObject, const char* variableName);
  151.  
  152. /*
  153.  * Given a class and a selector, return a pointer to the method's method
  154.  * structure.  Return NULL if not found. 
  155.  *
  156.  * This is a method internal to the run-time. 
  157.  */
  158. Method_t  
  159. searchForMethodInHierarchy (Class_t, SEL);
  160.  
  161.  
  162. /*
  163.  * class_getInstanceMethod() returns a pointer 
  164.  *  to the data structure that describes the method.  
  165.  *
  166.  * The selector must identify an 
  167.  *  instance method.
  168.  *
  169.  * Return a NULL pointer if aSelector doesn't 
  170.  *  identify a method defined in or inherited 
  171.  *  by aClass.
  172.  */
  173. static inline Method_t  
  174. class_getInstanceMethod (Class_t aClass, SEL aSel) {
  175.  
  176.   return searchForMethodInHierarchy (aClass, aSel);
  177. }
  178.  
  179. /*
  180.  * class_getClassMethod() returns a pointer to 
  181.  *  the data structure that describes the method.  
  182.  *
  183.  * The selector must identify a class (factory) method.  
  184.  *
  185.  * Return a NULL pointer if aSelector doesn't 
  186.  *  identify a method defined in or inherited by aClass.
  187.  */
  188. static inline Method_t  
  189. class_getClassMethod (MetaClass_t aClass, SEL aSel) {
  190.  
  191.   return searchForMethodInHierarchy ((Class_t)aClass, aSel);
  192. }
  193.  
  194. /*
  195.  * This function returns the name of aObject's 
  196.  *  class.  anObject should be an instance 
  197.  *  object, not a class object.
  198.  */
  199. static inline const char* 
  200. object_getClassName (id aObject) {
  201.  
  202.   return aObject->isa->name;
  203. }
  204.  
  205. /*
  206.  * This function returns the name of the 
  207.  *  class. 
  208.  */
  209. static inline const char* 
  210. class_getClassName (Class_t aClassObject) {
  211.  
  212.   return aClassObject->name;
  213. }
  214.  
  215. /*
  216.  * The first function, sel_getUid(), returns a selector that's 
  217.  *  used at run time to identify the aName method.  Whenever 
  218.  *  possible, you should use the @selector() directive to 
  219.  *  ask the compiler, rather than the run-time system, 
  220.  *  to provide the selector for a method.  This function 
  221.  *  should be used only if the name isn't known at compile 
  222.  *  time.
  223.  *
  224.  * The second function, sel_getName(), is the inverse 
  225.  *  of the first.  It returns the name that was mapped to 
  226.  *  aSelector.
  227.  */
  228. SEL    
  229. sel_getUid (const STR);
  230.  
  231. const STR    
  232. sel_getName (SEL);
  233.  
  234. /*
  235.  * class_addInstanceMethods() adds methods that can be 
  236.  *  used by instances of the class and class_addClassMethods() 
  237.  *  adds methods used by the class object.  Before adding a 
  238.  *  method, both functions check for duplicates.  A warning 
  239.  *  is sent to the standard error stream if any ambiguities exist.
  240.  *
  241.  * The passed structure and its contents must exist for the the
  242.  *  duration of the program.  These functions don't support
  243.  *  linked structures.
  244.  */
  245. static inline void  
  246. class_addInstanceMethods (Class_t aClass, MethodList_t aMethodList) {
  247.  
  248.   addMethodsToClass (aClass, aMethodList);
  249. }
  250.  
  251. static inline void  
  252. class_addClassMethods (Class_t aClass, MethodList_t aMethodList) {
  253.  
  254.   addMethodsToClass ((Class_t)aClass->isa, aMethodList);
  255. }
  256.  
  257. /*
  258.  * This function returns the number of bytes that all of aMethod's
  259.  *  arguments, taken together, would occupy on the stack.
  260.  */
  261. static inline u_int 
  262. method_getSizeOfArguments (Method_t aMethod) {
  263.  
  264.   return atoi (&aMethod->method_types[1]);
  265. }
  266.  
  267. /*
  268.  * This function returns the size in bytes of a 
  269.  *  instance of aObject.
  270.  */
  271. static inline long
  272. objc_classSize (id aObject) {
  273.   
  274.   return aObject->isa->instance_size;
  275. }
  276.  
  277. /* 
  278.  * This function returns the number of arguments that aMethod
  279.  *  the takes.  This will be at least two, since it 
  280.  *  includes the “hidden” arguments, self and _cmd, 
  281.  *  which are the first two arguments passed to every 
  282.  *  method implementation.
  283.  */
  284. u_int 
  285. method_getNumberOfArguments (Method_t aMethod);
  286.  
  287. /* This functiontakes an index into aMethod's argument 
  288.  *  list and returns, by reference, the type of the argument 
  289.  *  and the offset to the location of that argument in the 
  290.  *  list.  Indices begin with 0.  The “hidden” arguments 
  291.  *  self and _cmd are indexed at 0 and 1; method-specific 
  292.  *  arguments begin at index 2.  The offset is measured in 
  293.  *  bytes and depends on the size of arguments preceding the 
  294.  *  indexed argument in the argument list.  The type is 
  295.  *  encoded according to the conventions of the @encode() 
  296.  *  compiler directive.
  297.  */
  298. u_int 
  299. method_getArgumentInfo (Method_t aMethod, 
  300.                                 int indx, const char **type, int *offset);
  301.  
  302. /*
  303.  * This function is used to support archiving when a unknown class is to read
  304.  *  from a archive.  This function returns a instantiated object.  To further
  305.  *  dearchive the object it should be sent: -readFrom:.
  306.  *
  307.  * This function positions the file pointer just past class Object's class
  308.  *  data.
  309.  */
  310. id  
  311. objc_objectFromFile (int aFd);
  312.  
  313.  
  314. /* Some functions that I've been told are useful by Henry Flurry */
  315.  
  316. /* Returns a C string representing the ASCII rep of the selector. */
  317. static inline const char*
  318. SELNAME(SEL sel) {
  319.  
  320.  
  321.     return sel_getName (sel);
  322. }
  323.  
  324. /*
  325.  * Converts a C string to a SEL that can be used in perform: methods,
  326.  * objc_msgSend(), etc. 
  327.  */
  328. static inline SEL
  329. SELUID(const STR str) {
  330.  
  331.     return sel_getUid (str);
  332. }
  333.  
  334. /*
  335.  * Returns the class name of the object (or meta class name of a class
  336.  * object), or some _nilName if obj is nil. 
  337.  */
  338. static inline const char*
  339. NAMEOF(id obj) {
  340.  
  341.     const char*    theName = NULL;
  342.  
  343.  
  344.     if (obj)
  345.         if (obj->isa->info & CLS_CLASS)
  346.             theName = object_getClassName (obj);
  347.         else
  348.             if (((Class_t)obj)->isa->info & CLS_META)
  349.                 theName = class_getClassName ((Class_t)obj);
  350.     
  351.     return theName;
  352. }
  353.  
  354.  
  355. #endif
  356.  
  357.